
// pages/login/login.js

const app = getApp()

Page({

  data: {
    username: '',
    password: ''
  },

  userName: function (event) {
    console.log(event.detail.value)
    this.setData({
      username: event.detail.value
    })
  },
  password: function (e) {
    console.log(e.detail.value)
    this.setData({
      password: e.detail.value
    })
  },
  btnLoginClick: function (e) {
    //获取当前已经赋值的用户名和密码
    var name = this.data.username;
    var pass = this.data.password;
    //此处定死了用户名和密码,如果不正确,给出提示
    if (name != 'admin' || pass != 111111) {
      wx.showToast({
        title: '密码错误',
        duration: 2000
      })
    } else {//信息正确弹出检测账户的提示框
      wx.showLoading({
        title: '登陆中',
      })
      //信息正确,给userInfo赋值
      app.globalData.userInfo = { username: this.data.username, password: this.data.password }
      //将用户名和密码缓存下来,留着实现不用重复登录  
      wx.setStorageSync("username", this.data.username)
      wx.setStorageSync("password", this.data.password)
      //跳转页面,并且关闭当前页面
      wx.switchTab({
        url: '../test/test',
        success: function (e) {
          var page = getCurrentPages().pop();
          if (page == undefined || page == null) return;
          page.onLoad();
        }
      })
    }
  }
})